from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import os


class RegisterLogin:
    def __init__(self):
        # 打开浏览器
        self.driver = webdriver.Chrome()
        # 获取动态地址
        self.url = 'file:///' + os.path.abspath('html') + '/注册实例.html'
        self.driver.get(self.url)
        # 最大化
        self.driver.maximize_window()

    def frist_register(self):
        # 输入信息
        self.driver.find_element(By.ID, 'user').send_keys('123456')
        self.driver.find_element(By.ID, 'password').send_keys('123456')
        self.driver.find_element(By.ID, 'tel').send_keys('12345678910')
        self.driver.find_element(By.ID, 'email').send_keys('123456@qq.com')
        time.sleep(2)
        # 点击登录按钮
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def second_register(self):
        # 切换frame页面
        self.driver.switch_to.frame('idframe1')
        # 输入信息
        self.driver.find_element(By.ID, 'userA').send_keys('123456')
        self.driver.find_element(By.ID, 'passwordA').send_keys('123456')
        self.driver.find_element(By.ID, 'telA').send_keys('12345678910')
        self.driver.find_element(By.ID, 'emailA').send_keys('123456@qq.com')
        time.sleep(2)
        # 点击登录
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def third_register(self):
        # 返回到最上层页面
        self.driver.switch_to.default_content()
        # 切换frame页面
        f3 = self.driver.find_element(By.XPATH, '/html/body/s/iframe[2]')
        self.driver.switch_to.frame(f3)
        # 输入信息
        self.driver.find_element(By.ID, 'userB').send_keys('123456')
        self.driver.find_element(By.ID, 'passwordB').send_keys('123456')
        self.driver.find_element(By.ID, 'telB').send_keys('12345678910')
        self.driver.find_element(By.ID, 'emailB').send_keys('123456@qq.com')
        time.sleep(2)
        # 点击登录
        self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button').click()

    def quit(self):
        time.sleep(2)
        # 退出浏览器
        self.driver.quit()


if __name__ == '__main__':
    r1 = RegisterLogin()
    r1.frist_register()
    r1.second_register()
    r1.third_register()
    r1.quit()
